package com.lizhi.note.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Data;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@Entity
@Table(name = "notepage")
@EntityListeners(AuditingEntityListener.class)
@Data
@SQLDelete(sql = "UPDATE notepage SET deleted = id  WHERE id = ?")
@Where(clause = "deleted = 0")
public class NotepageEntity extends BaseEntity{

    @NotBlank
    @Size(max = 20)
    private String title;

    private String summary;

    @Column(columnDefinition = "longtext")
    private String content;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "notebook_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    private NotebookEntity notebook;
}
